package common;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.net.ssl.SSLSocket;

public class Receiver extends Thread{

	private SSLSocket socket;
	private Buffer buffer;
	
	public Receiver(SSLSocket socket, Buffer buffer){
		this.socket = socket;
		this.buffer = buffer;
	}
	
	public void run(){
		BufferedReader in = null;
		try {
			in = new BufferedReader(
					new InputStreamReader(
				    socket.getInputStream()));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		while(true){
			String inputLine = null;
			while (inputLine == null){
				try {
					Thread.sleep(10);
					inputLine = in.readLine();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			buffer.offer(inputLine);
		}
	}
}
